Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> simplexml_load_file() a tag <1></1>
pampper
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.09.2007

Ostrzeżenie: (0%)
-----


Witam,

mam problem z prasowaniem pliku xml. Ładuję plik xml za pomocą simplexml_load_file(). W pliku xml znajduje się fragment:

  1. <zdjecia>
  2. <1>true</1>
  3. <2>true</2>
  4. <3>true</3>
  5. <4>true</4>
  6. <5>true</5>
  7. <6>true</6>
  8. <7>true</7>
  9. <8>true</8>
  10. <9>true</9>
  11. <10>true</10>
  12. <11>true</11>
  13. <12>true</12>
  14. <13>true</13>
  15. <14>true</14>
  16. <15>true</15>
  17. </zdjecia>


odpalając skrypt wywala mi error:

Warning: simplexml_load_file() [function.simplexml-load-file]: ./dane.xml:10: parser error : StartTag: invalid element name in /www/skrypt.php on line 15
Warning: simplexml_load_file() [function.simplexml-load-file]: <1></1> in /www/skrypt.php on line 15
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /www/skrypt.php on line 15
Warning: simplexml_load_file() [function.simplexml-load-file]: ./dane.xml:10: parser error : expected '>' in /www/skrypt.php on line 15
Warning: simplexml_load_file() [function.simplexml-load-file]: <1></1> in /www/skrypt.php on line 15
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /www/skrypt.php on line 15

skrypt.php on line 15 - to funkcja simplexml_load_file()

Kiedy natomiast z pliku xml wywalę ten fragment to skrypt działa poprawnie. Rozumiem, że chodzi tutaj o tagi <1></1> itd. bo jak zamieniłem na na <z1></z1> itd. to również chodziło dobrze.

Jak mogę rozwiązać ten problem, żeby odczytywał tagi <1></1> a nie wywalał error.
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




http://www.w3schools.com/XML/xml_elements.asp

Kod
XML Naming Rules

XML elements must follow these naming rules:

    Names can contain letters, numbers, and other characters
    --- Names cannot start with a number or punctuation character ---
    Names cannot start with the letters xml (or XML, or Xml, etc)
    Names cannot contain spaces

Ludzi... wiele lat istnienia xml-a, tak prostej struktury a oni nadal nie wiedzą jak powinien wyglądać.
A skoro to jest parser xml-a... (a nie stwora xml-owego) więc nie za bardzo zmusisz go do współpracy.
Go to the top of the page
+Quote Post
pampper
post
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.09.2007

Ostrzeżenie: (0%)
-----


Gdyby ktoś znał lepsze rozwiązanie niż moje poniższe, to chętnie wysłucham (IMG:style_emoticons/default/smile.gif)
  1.  
  2. $fp = fopen("dane.xml", "r");
  3. $noweDane = fread($fp, filesize("dane.xml"));
  4. fclose($fp);
  5. for($a=1; $a<16; $a++) {
  6. $noweDane = ereg_replace("<".$a.">", "<z".$a.">", $noweDane);
  7. $noweDane = ereg_replace("</".$a.">", "</z".$a.">", $noweDane);
  8. }
  9. $fp = fopen("dane.xml", "w");
  10. fputs($fp, $noweDane);
  11. fclose($fp);
  12.  
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.08.2025 - 09:52